package com.shanzmoo.db.produce.entity.dto;

import com.alibaba.fastjson.JSON;
import com.shanzmoo.db.produce.entity.FactoryOrderDetailEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;

/**
 * 生产订单明细保存对象
 *
 * @author: Gzhao 2020/12/15
 */
@Data
@ApiModel("生产订单明细保存对象")
public class FactoryOrderDeatailSaveDto implements Serializable {

    private static final long serialVersionUID = 1758L;

    @NotBlank(message = "商品编码不允许为空")
    @ApiModelProperty(value = "商品编码", example = "123456")
    private String sku;

    @NotBlank(message = "商品名称不允许为空")
    @ApiModelProperty(value = "商品名称", example = "测试商品")
    private String skuName;

    @NotBlank(message = "商品单位不允许为空")
    @ApiModelProperty(value = "商品单位", example = "个")
    private String unit;

    @NotBlank(message = "规格属性描述不允许为空")
    @ApiModelProperty(value = "规格属性描述", example = "白色，128g")
    private String attributeDesc;

    @NotNull(message = "商品数量不允许为空")
    @ApiModelProperty(value = "商品数量", example = "10")
    private Integer skuNum;

    public static List<FactoryOrderDetailEntity> createList(List<FactoryOrderDeatailSaveDto> deatailList, String productionNo) {
        List<FactoryOrderDetailEntity> reList = JSON.parseArray(JSON.toJSONString(deatailList), FactoryOrderDetailEntity.class);
        reList.forEach(e->{
            e.setProductionNo(productionNo);
        });

        return reList;
    }
}
